﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Windows;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using INTEX.DataBase;
using ReflectionStudio.Controls;
namespace WPFExcelReport
{
    public partial class YXCAD2ITXData
    { 
        public DataSet Convert2WASTAMM()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WASTAMM_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WASTAMM";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WASTAMM"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
               Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            if (dwIntex["WALAEAEND"].ToString() == "0")
            {
                dwIntex["WALAEAEND"] = "500";
            }

            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WDECK(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WDECK_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            } 
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        
        public DataSet Convert2WTGEW()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WTGEW_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WTGEW";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WTGEW"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }

        public DataSet Convert2WABIND()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WABIND_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];

            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "SDDAT";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WABIND"
                        orderby dwMap["FIELD"], System.Convert.ToInt16(dwMap["PART"].ToString())
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }

        public DataSet Convert2WTEINZ()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WTEINZ_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];

            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WTEINZ";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WTEINZ"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WTPASS()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WTPASS_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];

            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WTPASS";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WTPASS"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WASTPASS()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WASTPASS_MAP";
            DataTable tbMapID = new DataTable();
            string itxfield = "";
            tbMapID = SetCAD.Tables[mapID];

            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WASTPASS";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WASTPASS"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }
        public string Byte2String(byte[] arrByte)
        {

            StringBuilder sb = new StringBuilder();
            foreach (byte b in arrByte)
            {
                sb.Append(b > 15 ? Convert.ToString(b, 16) : '0' + Convert.ToString(b, 16));
            }
            return sb.ToString();
        }
        public Queue HandleWTSSCHUSS(Queue WRWRQueue, DataRow dwWTSCHUSS, string PatternPre, string RepeatePre)
        {
            Array WR, WM;
            string CellName = "";
            string CellValue = "";
            string WTBTAB;
            byte[] b;
            string FieldName = "WTSSCHUSS01";
            b = (byte[])(dwWTSCHUSS[FieldName]);
            WTBTAB = Byte2String(b);
            FieldName = "WTSSCHUSS02";
            b = (byte[])(dwWTSCHUSS[FieldName]);
            WTBTAB += Byte2String(b);

            //WTBTAB = "0002001E0000000000000000000300270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
            int ColStart = 0;
            WR = (Array)WRWRQueue.Dequeue();
            WM = (Array)WRWRQueue.Dequeue();
            string ColI = "";
            string WBi, WBj;
            int YarnI, EndsI, R1i, R2i, R3i, R4i;
            try
            {
                for (int i = 1; i <= 100; i++)
                {
                    //    "0002001E0000000000000000"
                    ColI = WTBTAB.Substring((i - 1) * 16, 16).ToUpper();
                    YarnI = System.Convert.ToInt16(ColI.Substring(0, 4), 16) - 1;
                    EndsI = Convert.ToInt32(ColI.Substring(4, 4), 16);
                    R1i = System.Convert.ToInt16(ColI.Substring(8, 4), 16);
                    WR.SetValue(R1i, 0, ColStart + i - 1);
                    R2i = System.Convert.ToInt16(ColI.Substring(12, 4), 16);
                    WR.SetValue(R2i, 1, ColStart + i - 1);
                    //EndsI = System.Convert.ToInt16(ColI.Substring(4, 4));

                    if (YarnI > -1)
                    {
                        WM.SetValue(EndsI, YarnI, ColStart + i - 1);
                    }
                }
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return WRWRQueue;
        }
        public DataSet Convert2WTSCHUSS()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WTSCHUSS_MAP";
            DataTable tbMapID = new DataTable();
            DataTable tbTechMaster = SetCAD.Tables["TechMaster"];

            string itxfield = "";

            tbMapID = SetCAD.Tables[mapID];

            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WTSCHUSS";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WTSCHUSS"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }
        public DataSet Convert2WAFINISH()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WAFINISH_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];
               DataTable tbIntex = new DataTable();
               tbIntex.TableName = "WAFINISH";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WAFINISH"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;

        }
        public DataSet Convert2WAFARBEN()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WAFARBEN_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];

            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WAFARBEN";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WAFARBEN"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;

        }
        public DataSet Convert2WASTGA()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WASTGA_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WASTGA";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "WASTGA"
                        select dwMap;
            var query1 = from dwYarn in SetEXT.Tables["TechDetail"].AsEnumerable()
                         where dwYarn["FIsWarp"].ToString() == "False"
                         orderby dwYarn["FCharValue"].ToString()
                         select dwYarn;
            foreach (DataRow dwYarn in query1)
            {
                foreach (DataRow dwTemp in query)
                {
                    Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwYarn);
                }
                if (dwYarn["FColorName"].ToString().Contains("原纱"))
                {
                    dwIntex["WAGGVAR"] = "   ";
                }
                if (dwYarn["FColorNO"].ToString() == "1")
                {
                    dwIntex["WAGGVAR"] = "   ";
                }
                if (dwIntex["WAGGFARBE"].ToString().Trim() == "")
                {
                    dwIntex["WAGGFARBE"] = "000000    ";
                }
                //dwIntex["WAGPOS"] = Right("00" + dwIntex["WAGFOLGEPOS"].ToString().Trim(), 2);
                tbIntex.Rows.Add(dwIntex);
                dwIntex = tbIntex.NewRow();
            }
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WASTKE()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WASTKE_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WASTKE";
            DataRow dwIntex = tbIntex.NewRow();

            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WASTKE"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }

            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }
        public DataSet Convert2BSSATZ()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "BSSATZ_MAP";
            DataTable tbMapID = new DataTable();

            string itxfield = "";
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "BSSATZ";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "BSSATZ"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }

            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }
        public DataSet Convert2BHSATZ()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "BHSATZ_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "BHSATZ";
            DataRow dwIntex = tbIntex.NewRow();

            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "BHSATZ"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }
        public DataSet Convert2BSGROE(string machinetype, string beamtype)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "BSGROE_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "BSGROE";
            DataRow dwIntex = tbIntex.NewRow();


            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "BSGROE"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            dwIntex["BSGMTYP"] = Left(machinetype + "       ", 8);
            dwIntex["BSGKETTART"] = Left(beamtype + "       ", 6);
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2BSFARB()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "BSFARB_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "BSFARB";
            DataRow dwIntex = tbIntex.NewRow();

            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "BSFARB"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }

            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);

            return setReturn;
        }
        public DataSet Convert2BASTGA()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "BASTGA_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "BASTGA";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "BASTGA"
                        select dwMap;
            var query1 = from dwYarn in SetEXT.Tables["TechDetail"].AsEnumerable()
                         where dwYarn["FIsWarp"].ToString().Trim() == "True"
                         orderby dwYarn["FCharValue"].ToString()
                         select dwYarn;
            foreach (DataRow dwYarn in query1)
            {
                foreach (DataRow dwTemp in query)
                {
                    Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwYarn);
                }
                dwIntex["BAGPOS"]=Right("00" + dwIntex["BAGPOS"].ToString(), 2);
                if (dwYarn["FColorName"].ToString().Contains("原纱"))
                {
                    dwIntex["BAGGVAR"] = "   ";
                }
                if (dwYarn["FColorNO"].ToString() == "1")
                {
                    dwIntex["BAGGVAR"] = "   ";
                }
                if (dwIntex["BAGGFARBE"].ToString().Trim() == "")
                {
                    dwIntex["BAGGFARBE"]= "000000    ";
                }
                tbIntex.Rows.Add(dwIntex);
                dwIntex = tbIntex.NewRow();
            }
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2BASTGAD()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "BASTGAD_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "BASTGAD";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "BASTGAD"
                        select dwMap;
            var query1 = from dwYarn in SetCAD.Tables["TechDetail"].AsEnumerable()
                         where dwYarn["FIsWarp"].ToString().Trim() == "True"
                         orderby dwYarn["FCharValue"].ToString()
                         select dwYarn;
            foreach (DataRow dwYarn in query1)
            {
                foreach (DataRow dwTemp in query)
                {
                    Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwYarn);
                }
                dwIntex["BAGPOS"] = Right("00" + dwIntex["BAGPOS"].ToString(), 2);
                if (dwYarn["FColorName"].ToString().Contains("原纱"))
                {
                    dwIntex["BAGGVAR"] = "   ";
                }
                if (dwIntex["BAGGFARBE"].ToString().Trim() == "")
                {
                    dwIntex["BAGGFARBE"] = "000000    ";
                }
                tbIntex.Rows.Add(dwIntex);
                dwIntex = tbIntex.NewRow();
            }
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WTSAER()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WTSAER_MAP";
            DataTable tbMapID = new DataTable();
            int seq = 0;
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WTSAER";
            DataRow dwIntex = tbIntex.NewRow();
            string yarnx = "WTBGARN";
            string countx = "WTBFDZ";
            string yarnn = "WTBFNR1";
            
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "WTSAER"
                        select dwMap;
            var query1 = from dwYarn in SetEXT.Tables["TechDetail"].AsEnumerable()
                         where dwYarn["FIsWarp"].ToString().Trim() == "True"
                         orderby dwYarn["FCharValue"].ToString()
                         select dwYarn;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            seq = 1;
            int ends = 1;
            int totalends = 0;
            foreach (DataRow dwYarn in query1)
            {
                ends=System.Convert.ToInt32(dwYarn["FThreadCountAll"].ToString());
                dwIntex["WTBGARN" + seq.ToString()] = dwYarn["FThreadChar"];
                dwIntex["WTBFDZ" + seq.ToString()] = ends;
                dwIntex["WTBFNR" + seq.ToString()] = seq;
                dwIntex["WTBANZFAE" + seq.ToString()] =ends;
                totalends += ends;
                seq++;
            }
            dwIntex["WTBSRAPP"] = totalends;
            dwIntex["WTBANZFARB"] = seq-1;
            tbIntex.Rows.Add(dwIntex);
            dwIntex = tbIntex.NewRow();
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet GetProcessFlow(string stage, string art, string var, string color, string matchid)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string expression = "";
            if (matchid.Trim() == "")
            {
                expression = "STAGE='" + stage + "'";
            }
            else
            {
                expression = "STAGE='" + stage + "' AND MATCHID='" + matchid + "'";
            }
            DataRow[] rows = SetCAD.Tables["DATADISPO"].Select(expression);
            if (rows.Length>0)
            {
                setReturn.Merge(rows);
            }
            return setReturn;
        }
        private DataSet GetLoomType(string loomtype)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string expression = "";           
            DataRow[] rows = SetCAD.Tables["LOOMTYPE"].Select();
            if (rows.Length > 0)
            {
                setReturn.Merge(rows);
            }
            return setReturn;
        }
        public DataSet Convert2APZUORD(string stage, string art, string var, DataRow dwFlow)
        {
            //ITXART ITXVAR ITXAPKRS ITXAPLFD ITXATYPE ITXPDES
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "APZUORD_MAP";
            DataTable tbMapID = new DataTable(); 
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "APZUORD";
            DataRow dwIntex = tbIntex.NewRow();
            string apkrs, aplfd, apdes;
            apkrs = dwFlow["APKRS"].ToString();
            aplfd = dwFlow["APNR"].ToString();
            apdes=dwFlow["MATCHTYPE"].ToString();
            apdes = (string)gb2312.ConvertBack(apdes, null, null, null);
            apdes = Left(apdes + "                                                         ", 50);
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "APZUORD"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            dwIntex["APZART"] = art;
            dwIntex["APZVAR"] = Left(var+"   ",3);
            dwIntex["APZANRKRS"] = apkrs;
            dwIntex["APZALFDNR"] = aplfd;
            dwIntex["APZSTUFE"] = stage;
            dwIntex["APZSPEZIF"] = apdes; 
            tbIntex.Rows.Add(dwIntex);
            dwIntex = tbIntex.NewRow();
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2GSCOLOR(string yart, string yvar, string ycolor, string ydesc)
        {
            //ITXART ITXVAR ITXAPKRS ITXAPLFD ITXATYPE ITXPDES
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "GSCOLOR_MAP";
            DataTable tbMapID = new DataTable(); 
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "GSCOLOR";
            DataRow dwIntex = tbIntex.NewRow();           
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "GSCOLOR"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp);
            }
            dwIntex["GSCART"] = yart;
            dwIntex["GSCVAR"] = yvar;
            dwIntex["GSCFARBE"] = ycolor;
            dwIntex["GSCBEZ"] = ydesc;
            tbIntex.Rows.Add(dwIntex);
            dwIntex = tbIntex.NewRow();
            setReturn.Merge(tbIntex);
            return setReturn;
        } 
    }
}
